/*******************************************************************************
 * Copyright (c) 2005, 2014 springside.github.io
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *******************************************************************************/
package com.waijiaojun.tpo.rest;

import org.springframework.http.HttpStatus;

/**
 * 专用于Restful Service的异常.
 *
 */
public class RestServerException extends RuntimeException {


	private int status = HttpStatus.INTERNAL_SERVER_ERROR.value();
	private Long timestamp = System.currentTimeMillis();
	private String message;// 给用户看到友好的消息，提示用户错误原因，或者碰到这个错误该如何操作
	private String errorDetail;// 给开发看的错误详情，用于定位错误原因。
	public String toJson(){
		return "{\"status\":"+status+", \"timestamp\":"+timestamp+", \"message\":\""+message+"\", \"errorDetail\":\""+errorDetail+"\"}";
	}
	public RestServerException() {
	}

	public RestServerException(String message) {
		super(message);
		this.message = message;
	}

	public RestServerException(String message, String errorDetail) {
		super(message);
		this.message = message;
		this.errorDetail = errorDetail;
	}

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

	public Long getTimestamp() {
		return timestamp;
	}

	public void setTimestamp(Long timestamp) {
		this.timestamp = timestamp;
	}

	@Override
	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public String getErrorDetail() {
		return errorDetail;
	}

	public void setErrorDetail(String errorDetail) {
		this.errorDetail = errorDetail;
	}
}
